{extend name="main/index" /}
{block name="main"}
<div class="main-content">
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                
            </li>
            <li class="active">全部新闻</li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
            <form class="form-search">
                <span class="input-icon">
                    <input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
                    <i class="icon-search nav-search-icon"></i>
                </span>
            </form>
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="table-responsive">
                            <a href="{:url('admin/news/add')}" class="btn btn-info">添加新闻</a>
                            <br><br>
                            <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>新闻名称</th>
                                        <th>标题</th>
                                        <th>内容</th>
                                        <th class="hidden-480">照片</th>
                                        <th class="hidden-480">状态</th>
                                        <th class="hidden-480">操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {volist name="news" id="v"}

                                    <tr>
                                        <td>{$v['id']}</td>
                                        <td>{$v['name']}</td>
                                        <td>{$v['title']}</td>
                                        <td style="width:200px;height:100px;overflow-y:hidden visible auto;">{$v['content']}</td>
                                        <td><img src="{$v['image']}" style="width:150px;"></td>
                                        <td>
                                            {$v['status']==1?'开启':'关闭'}
                                        </td>
                                        <td>
                                            <a href="{:url('admin/news/edit', ['id' => $v['id']])}" class="btn btn-primary">修改</a> |
                                            <button data-id="{$v['id']}" class="btn btn-danger del-btn">删除</button>
                                        </td>
                                    </tr>
                                    {/volist}

                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}



{block name="myjs"}
{js href="/static/admin/assets/js/toastr.min.js"}
<script>
    $(function(){
        $('.del-btn').click(function () {
            var ac_id = $(this).attr('data-id');
            console.log('我要删除: ' + ac_id + '的新闻动态');
            if (confirm('你确定要 [ 删 除 ] 吗?')) {
                var obj = $(this).parents('tr');
                // console.log(obj);
                delAjax(ac_id, obj);
            }
        });

    });

    // 执行ajax删除
    function delAjax(id, obj) {
        $.ajax({
            type: 'delete',
            url: '/News/' + id,
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data.status) {
                    toastr.success(data.info);
                    obj.remove();
                } else {
                    toastr.error(data.info, 'FBI WARNING:');
                }
            },
            error: function () {
                alert('AJAX执行失败');
            }
        });
    }

</script>

{/block}








